package cn.wangliang181230.maven.plugins.mytest;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

/**
 * Print Context Mojo
 */
@Mojo(name = "print", defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true)
public class PrintMojo extends AbstractMojo {

	@Parameter(property = "wl.mytest.skip", defaultValue = "false")
	private boolean skip;

	@Parameter(property = "wl.mytest.skip-print", defaultValue = "false")
	private boolean skipPrint;

	@Override
	public void execute() throws MojoExecutionException, MojoFailureException {
		if (skip || skipPrint) {
			getLog().info("mytest-maven-plugin:print are skipped.");
			return;
		}

		SerializerFeature[] features = new SerializerFeature[]{
				SerializerFeature.PrettyFormat, // 格式化输出JSON
				SerializerFeature.WriteClassName // 输出类名"@type"
		};
		System.out.println("plugin context:\r\n" + JSON.toJSONString(super.getPluginContext(), features));
	}
}
